﻿using Cysharp.Threading.Tasks;
using UnityEngine;

/// <summary>
/// 跳跃
/// </summary>
public class FSMStateJump : FSMStateBase
{
    protected override string getName => "jump";

    public override bool isLoop { get; } = false;

    public override int priority { get; } = UnitDefine.STATE_PRIORITY_NON_INTERRUPTIBLE;

    private float speed => UnitDefine.BASE_SPEED * fsm.entity.attribute.speed;
    private float jumpHeight => UnitDefine.BASE_JUMP_HEIGHT;  // TODO 添加属性修正

    protected override void OnEnter()
    {
        Jump();
    }

    private async void Jump()
    {
        var initialSpeedY = fsm.entity.physics.FFMEndSpeed(jumpHeight);
        var axis = fsm.parameters.GetParam<float>("horizontalAxis");
        var initialSpeedX = axis * speed;
        fsm.entity.physics.velocity = new Vector2(initialSpeedX, initialSpeedY);
        await UniTask.DelayFrame(1);
        isEnd = true;
    }
}